/*
** $Id: parseIPV4.c 10 2014-08-24 13:20:16Z chupin007@gmail.com $
** $HeadURL: http://bapps.googlecode.com/svn/trunk/src/enc/src/parseIPV4.c $
*/
#include <stdio.h>
#include <stdlib.h>

void parseIPV4( unsigned char *ipv4, unsigned char *ipv4bytes ) {

  int n;
  unsigned ipbyte3, ipbyte2, ipbyte1, ipbyte0;
  
  n = sscanf( ipv4, "%d.%d.%d.%d", &ipbyte3, &ipbyte2, &ipbyte1, &ipbyte0 );
  if( n != 4 || ipbyte3 > 255 || ipbyte2 > 255 || ipbyte1 > 255 || ipbyte0 > 255 ) {
    fprintf( stderr, "wrong format of IPv4 address: %s\n", ipv4 );
    exit( 1 );
  }
  ipv4bytes[0] = ipbyte3;
  ipv4bytes[1] = ipbyte2;
  ipv4bytes[2] = ipbyte1;
  ipv4bytes[3] = ipbyte0;

}
